package co.fitstart.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;

@Dynamic("hibernate")
public interface SiteDao {
    
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Site WHERE is_disabled = false AND financeCode IS NOT NULL")
    public List<Site> listUnEmptyCodeSite(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Site WHERE is_disabled = false AND financeCode IS NULL")
    public List<Site> listEmptyCodeSite(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

    /**
     * 
     * @param areaManager
     * @return
     */
    @Query("FROM Site WHERE areaManager=:areaManager")
    public List<Site> listSitesForAreaManager(@Variable("areaManager") Principal areaManager);
    
    /**
     * 
     * @param areaServer
     * @return
     */
    @Query("FROM Site WHERE areaServer=:areaServer")
    public List<Site> listSitesForAreaServer(@Variable("areaServer") Principal areaServer);
    
    /**
     * 
     * @param siteManager
     * @return
     */
    @Query("SELECT relation.site FROM PrincipalReportRelation relation WHERE relation.manager = :siteManager AND relation.coach IS NULL")
    public Site loadForSiteManager(@Variable("siteManager") Principal siteManager);
    
    /**
     * 
     * @param siteServer
     * @return
     */
    @Query("SELECT relation.site FROM PrincipalReportRelation relation WHERE relation.coach = :siteServer AND relation.manager IS NULL")
    public Site loadForSiteServer(@Variable("siteServer") Principal siteServer);
    
    /**
     * 
     * @return
     */
    @Query("SELECT DISTINCT city FROM Site")
    public List<String> loadAllCity();
    
    /**
     * 
     * @param name
     * @return
     */
    @Query("FROM Site WHERE name = :name")
    public Site load(@Variable("name") String name);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM Site WHERE code = :code")
    public Site loadByCode(@Variable("code") String code);

    /**
     * 
     * @return
     */
    @Query("FROM Site WHERE disabled = false")
    public List<Site> list();
}
